import { GetFileUrl } from '@/services/index';
import React, { FC, useEffect, useState } from 'react';
import styles from './index.module.less'

interface FilePreviewProps {
  match: {
    params: { id: string };
  };
}



// 根据文件id预览pdf
const FilePreviewPdf: FC<FilePreviewProps> = (props) => {

  const [pdfUrl, setFileInfo] = useState<string | null>();

  useEffect(() => {
    // let CREATE_IMG = require('@/assets/1111.pdf');
    getFile();
  }, []);

  const getFile = async () => {
    const href = await GetFileUrl({ id: props.match.params.id, device: 'H5' });
    console.log('href.data', href.data)
    setFileInfo(href.data);
  };


  // 再 ios 端使用  iframe 会有问题，无法滚动翻页
  return (
    <div className={styles['show-iframe']}>
      {
        pdfUrl &&
        <iframe src={pdfUrl} width="100%" height="100%" scrolling="auto"></iframe>

        // // <object data={pdfUrl} type="application/pdf" width="100%" height="100%">
        // // </object>
        // <object data={pdfUrl} type="application/pdf" width="100%" height="100%">

        //   <iframe src={pdfUrl} width="100%" height="100%" >

        //     This browser does not support PDFs. Please download the PDF to view it: <a href={pdfUrl}>Download PDF</a>

        //   </iframe>

        // </object>

      }
    </div>
  );
};

export default FilePreviewPdf;